package datastructure.tree;

/**
 * http://www.leetcode.com/2010/11/largest-binary-search-tree-bst-in_22.html
 * http://www.geeksforgeeks.org/archives/7291
 *
 * @author Lei
 */
public class FindLargestBSTSubtree {

    // just return the largest cout size
    public int findLargestBSTSubtree(TreeNode root) {
        if (CheckBinaryTree.isBinarySearchTree(root, root.value, root.value)) {
            return GetNodeCount.getNodeCount(root);
        }
        else {
            return Math.max(findLargestBSTSubtree(root.left), findLargestBSTSubtree(root.right));
        }

    }
}
